package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.SevenNineNineSixDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.snns.SevenNineNineSixProduct;

@Repository("sevenNineNineSixDAO")
public class SevenNineNineSixDAOImpl extends SuperDAO<SevenNineNineSixProduct>
		implements SevenNineNineSixDAO {

	@Override
	public void insertProduct(SevenNineNineSixProduct product) {
		this.getSqlSession().insert("mybatis.xml.SnnsProductMapper.insert",
				product);
	}

	@Override
	public void updateProduct(SevenNineNineSixProduct product) {
		this.getSqlSession().update("mybatis.xml.SnnsProductMapper.update",
				product);
	}

	@Override
	public SevenNineNineSixProduct queryById(String id) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.SnnsProductMapper.selectByPrimaryKey", id);
	}

	@Override
	public SevenNineNineSixProduct queryByProductId(String productId) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.SnnsProductMapper.queryByProductId", productId);
	}

	@Override
	public Pagination<SevenNineNineSixProduct> queryProdutPage(
			SevenNineNineSixProduct query) {
		Pagination<SevenNineNineSixProduct> paginationList = null;
		Integer rowCount = queryRowCount(query);
		query.calculate();
		List<SevenNineNineSixProduct> list = queryGoodsInfoList(query);
		paginationList = this.queryPagination(rowCount, list, query);
		return paginationList;
	}

	@Override
	public List<SevenNineNineSixProduct> queryAllProduct(
			SevenNineNineSixProduct isAudit) {
		return this.getSqlSession().selectList(
				"mybatis.xml.SnnsProductMapper.queryAllSnnsInfo", isAudit);
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(SevenNineNineSixProduct info) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.SnnsProductMapper.queryRowCount", info);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<SevenNineNineSixProduct> queryGoodsInfoList(
			SevenNineNineSixProduct info) {
		List<SevenNineNineSixProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.SnnsProductMapper.querySnnsGoodsInfoList", info);
		return list;
	}
}
